<?php

/**
 * Return a themed breadcrumb trail.
 *
 * @param $breadcrumb
 *   An array containing the breadcrumb links.
 * @return a string containing the breadcrumb output.
 */
function epimetheus_breadcrumb($variables)
{

//    $breadcrumb = $variables['breadcrumb'];
//
//    if (!empty($breadcrumb)) {
//        // Provide a navigational heading to give context for breadcrumb links to
//        // screen-reader users. Make the heading invisible with .element-invisible.
//        $heading = '<h2 class="element-invisible">' . t('You are here') . '</h2>';
//        // Uncomment to add current page to breadcrumb
//        // $breadcrumb[] = drupal_get_title();
//        return '<nav class="breadcrumb">' . $heading . implode(' » ', $breadcrumb) . '</nav>';
//    }

}
### return currect city by url domain ###
function get_city_by_url() {
    global $infopark;
    return $infopark->get_city_by_url();
/*

$t=db_select("citydomain","c")->fields("c")->condition('url','http://'.$_SERVER['HTTP_HOST'])->execute()->fetchAssoc();


	$current_city = 0;
	$current_city_name = "";
	$result = array ();
	$result['current_city'] = $t['tid'];
	$result['current_city_name'] = $t['name'];
	return $result;*/
}	
### return all cities_list ###
function cities_list()
{
    global $infopark;
    return $infopark->cities_list();
/*$cities_rec=db_select("citydomain","c")->fields("c")->execute();
	
	while($c=$cities_rec->fetchObject())
		{
		$cities_list[$c->tid]=$c->name;
	
		}
		return $cities_list;*/
}
function get_user_city()
{

	require_once(DRUPAL_ROOT . "/themes/epimetheus/library/geoplugin.class.php");

	$geoplugin = new geoPlugin();
	$geoplugin->locate();
        
	$city = $geoplugin->city;
        if($_SERVER['REMOTE_ADDR']='5.29.34.66')$city='Kharkiv';
        echo "<!--CITYIS:".$city."-->";
$t_city=db_select("citydomain","c")->condition('c.name_en',Q($city,1))->fields("c")->execute()->fetchObject();

#print "<!--xxx-->";
if($t_city->id)return array($t_city->url, $t_city->name);
else return false;

	/*$availableCities = array('Kiev', 'Kerch', 'Kharkiv', 'Odessa');

	if (in_array($city, $availableCities)) {

		$citiesInRu = array(
			'Kiev'     => 'Киев',
			'Kerch'    => 'Керч',
			'Kharkiv'  => 'Харьков',
			'Odessa'   => 'Одесса'
		);

		return array($city, $citiesInRu[$city]);

	}

	return false;*/

}

/**
 * Duplicate of theme_menu_local_tasks() but adds clearfix to tabs.
 */
function epimetheus_menu_local_tasks(&$variables)
{
    $output = '';

    if (!empty($variables['primary'])) {
        $variables['primary']['#prefix'] = '<h2 class="element-invisible">' . t('Primary tabs') . '</h2>';
        $variables['primary']['#prefix'] .= '<ul class="tabs primary clearfix">';
        $variables['primary']['#suffix'] = '</ul>';
        $output .= drupal_render($variables['primary']);
    }
    if (!empty($variables['secondary'])) {
        $variables['secondary']['#prefix'] = '<h2 class="element-invisible">' . t('Secondary tabs') . '</h2>';
        $variables['secondary']['#prefix'] .= '<ul class="tabs secondary clearfix">';
        $variables['secondary']['#suffix'] = '</ul>';
        $output .= drupal_render($variables['secondary']);
    }
    return $output;

}

/**
 * Override or insert variables into the block templates.
 *
 * @param $variables
 *   An array of variables to pass to the theme template.
 * @param $hook
 *   The name of the template being rendered ("block" in this case.)
 */
function epimetheus_process_block(&$variables, $hook)
{
    // Drupal 7 should use a $title variable instead of $block->subject.
    $variables['title'] = $variables['block']->subject;

}

/**
 * Changes the search form to use the "search" input element of HTML5.
 */
function epimetheus_preprocess_search_block_form(&$vars)
{
    $vars['search_form'] = str_replace('type="text"', 'type="search"', $vars['search_form']);

}

function epimetheus_main_menu_modifier($html)
{

    $request_uri = $_SERVER['REQUEST_URI'];

    if (preg_match('/^\/places\//', $request_uri)) {
        $html = str_replace('"><a href="/places">', ' active"><a href="/places" class="active-trail active">', $html);
    }

    if (preg_match('/^\/events\//', $request_uri)) {
        $html = str_replace('"><a href="/events">', ' active"><a href="/events" class="active-trail active">', $html);
    }

    return $html;

}

function epimetheus_preprocess_page(&$vars)
{
    if (isset($vars['node']))
    {
        $node_type = $vars['node']->type;

        $content_types_without_view = array('schedule', 'brand');

        if (in_array($node_type, $content_types_without_view) &&
                arg(2) != 'edit' &&
                arg(2) != 'add' &&
                arg(2) != 'delete')
        {
            drupal_not_found();
            exit;
        }
    }
    /*if (arg(0) == 'taxonomy') {
    $variables['theme_hook_suggestions'][] = 'page__taxonomy';
  }*/
}

function get_places_by_brand($nid)
{
    $query = db_select('node', 'n');

    $query->leftJoin('field_data_field_place_brand', 'fb', 'n.nid = fb.entity_id');

    $query->fields('n', array('title', 'nid','status'))
            ->condition('fb.field_place_brand_nid', $nid, '=');

    $result = $query->execute()->fetchAll();

    return $result;
}

function gallery_view_prev($gallery_id) {

  $node = node_load($gallery_id);//$element['#node'];

  $image = get_img_by_id($node->media_gallery_media['und'][0]['fid']) ;

  if (!isset($image)) {
        $image = theme('image', array('path' => drupal_get_path('module', 'media_gallery') . '/images/empty_gallery.png'));
  }



    $output = '<div class="media-collection-item-wrapper">
                <div class="media-gallery-item">
                    <div class="gallery-thumb-outer">
                        <div class="gallery-thumb-inner">
                            <a class="media-gallery-thumb" href="javascript:;" id="gallery_'.$gallery_id.'"><img width="450" height="450" src="'.$image.'" alt="" ></a>
                        </div>
                    </div>
                </div>
            </div>';
  return $output;
}

function get_img_by_id($id) {
    $query = db_select('file_managed', 'files');

    $query->fields('files', array('uri', 'filemime'))
            ->condition('files.fid', $id, '=');

    $result = $query->execute()->fetchAll();

    if($result[0]->filemime === 'video/youtube') {
          $data = explode('/',$result[0]->uri) ;
          $image = 'http://infopark.com.ua/sites/default/files/styles/media_gallery_thumbnail/public/media-youtube/'.end($data).'.jpg';

    } else {
        $image = 'http://infopark.com.ua/sites/default/files/styles/media_gallery_thumbnail/public/'.substr($result[0]->uri, 9);
    }

    return $image;
}

function get_gallery_package_by_node_id($id) {

    $query = db_select('taxonomy_index', 'ta_id');

    $query->leftJoin('taxonomy_term_data', 'ta_td', 'ta_id.tid = ta_td.tid');

    $query->fields('ta_id', array('tid'))
            ->condition('ta_id.nid', $id, '=')
            ->condition('ta_td.vid', 11, '=');

    $result = $query->execute()->fetchAll();
    return $result;
}


function get_gallery_liste_by_package_id($id) {

    $query = db_select('node', 'n');

    $query->leftJoin('taxonomy_index', 'ta_id', 'n.nid = ta_id.nid');

    $query->fields('n', array('nid','title'))
            ->condition('ta_id.tid ', $id , '=')
            ->condition('n.type', 'media_gallery', '=');

    $result = $query->execute()->fetchAll();

    return $result;
}

function get_img_list_by_gallery_id($id) {

    $query = db_select('field_data_media_gallery_media', 'medua_list');

    $query->leftJoin('field_data_media_title', 'media_title', 'medua_list.media_gallery_media_fid = media_title.entity_id');

    $query->leftJoin('field_data_media_description', 'media_description', 'medua_list.media_gallery_media_fid = media_description.entity_id');

    $query->leftJoin('file_managed', 'file_name', 'medua_list.media_gallery_media_fid = file_name.fid');

    $query->fields('medua_list', array('media_gallery_media_fid'))

            ->fields('media_description', array('media_description_value'))
            ->fields('media_title', array('media_title_value'))
            ->fields('file_name', array('uri'))

           ->condition('medua_list.entity_id ', $id , '=');

    $result = $query->execute()->fetchAll();

    return $result;
}

function get_thubnail_info($thubnail_id) {

    $query = db_select('field_data_media_gallery_media', 'medua_list');


    $query->fields('medua_list', array('media_gallery_media_fid'))

            ->fields('media_description', array('media_description_value'))
            ->fields('media_title', array('media_title_value'))
            ->fields('file_name', array('uri'))

           ->condition('medua_list.entity_id ', $thubnail_id , '=');

    $result = $query->execute()->fetchAll();

    return $result;
}



function get_current_city() {
    $pageURL = 'http';
    if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
    $pageURL .= "://";
    if ($_SERVER["SERVER_PORT"] != "80") {
    $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
    } else {
    $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
    }

    $current_city = 'all';

    if( !(strrpos($current_city, 'kharkiv-oblast') === false) ) {
        $current_city = 'kharkiv-oblast';
    }
    elseif (!(strrpos($current_city, 'kiev') === false)) {
        $current_city = 'kiev';
    }
    elseif (!(strrpos($current_city, 'odessa') === false)) {
        $current_city = 'odessa';
    }
    elseif (!(strrpos($current_city, 'kerch') === false)) {
        $current_city = 'kerch';
    }
    elseif (!(strrpos($current_city, 'kharkiv') === false)) {
        $current_city = 'kharkiv';
    }
    else {
        $current_city = 'all';
    }
    return $current_city;
}

/**
 *  This function add list of keywords to already existed list
 */

function epimetheus_html_head_alter(&$head_elements) {

if(isset($head_elements['metatags_quick_keywords']))	$head_elements['metatags_quick_keywords']['#attributes']['content'] = 'театры, кинотеатры, клубы, музеи, выставки, концерты, программа передач ТВ, кафе и рестораны '.$head_elements['metatags_quick_keywords']['#attributes']['content'];

}

/**
 * this function add keywords to front page
 */

function epimetheus_page_alter ($page) {

	if (drupal_is_front_page()) {
		$meta_description = array(
			'#type' => 'html_tag',
			'#tag' => 'meta',
			'#attributes' => array(
				'name' => 'keywords',
				'content' =>  'театры, кинотеатры, клубы, музеи, выставки, концерты, программа передач ТВ, кафе и рестораны'
			)
		);

		drupal_add_html_head($meta_description, 'meta_description');
	}
	if(arg(0)=='adverts')
	{
	// title
	$title = array(
                         '#type' => 'html_tag',
                         '#tag' => 'title',
                         '#value' => 'Инфопарк Обьявления',
                          
                      );
                      #pre($page);
                    #$variables['head_title']= "New Title";
                    drupal_add_html_head($title, 'title');           
        //metadescription            
         $meta_description = array(
			'#type' => 'html_tag',
			'#tag' => 'meta',
			'#attributes' => array(
				'name' => 'description',
				'content' =>  'Обьявления от Инфопарк. Обьявления в Украине,Деловые и Частные.'
			)
		);

		drupal_add_html_head($meta_description, 'meta_description');           
	 //key-words
                    $page_keywords = array(
                         '#type' => 'html_tag',
                         '#tag' => 'meta',
                         '#attributes' => array(
                          'name' => 'keywords',
                          'content' => 'обьявления, обьявления украина, украина,срочно, продам,ищу,куплю,сдам в аренду, сниму, недвижимость, работа,машины',
                            )
                      );
                drupal_add_html_head($page_keywords, 'page_keywords');
	}
	if(arg(0)=='node')
	{
	$nid=arg(1);
	$node=node_load(array('nid'=>$nid));
	if($node->type=='advert')
	{
	$node=_advert_get_node($node);
	 $custom_fields=advert_prepare_custom_fields_display($node->custom_fields);

	// title
	$title = array(
                         '#type' => 'html_tag',
                         '#tag' => 'title',
                         '#value' => $node->title.' Инфопарк Обьявления',
                          
                      );
                      #pre($page);
                    #$variables['head_title']= "New Title";
                    drupal_add_html_head($title, 'title');  
                     #drupal_add_html_head($title, 'title');           
        //metadescription            
        $keywords=array();
	$keywords=array_merge($keywords,explode(" ",$node->title));
	  $description=mb_substr($node->body['und'][0]['value'],0,100)."\n";
foreach($custom_fields as $field)
  {
  if($field->form_type!='checkboxes')
  {
  $description.=$field->name.":".$field->value->value_name.",\n";
  }elseif(!empty($field->value->value_name)){
  $description.=$field->value->value_name.",\n";
  }
    
 if(!empty($field->value->value_name)) $keywords[]=$field->value->value_name;
  
  
  }
         $meta_description = array(
			'#type' => 'html_tag',
			'#tag' => 'meta',
			'#attributes' => array(
				'name' => 'description',
				'content' =>  $description
			)
		);            
	drupal_add_html_head($meta_description, 'meta_description');  	
	//key-words
	
	
	$keywords=array_merge($keywords,explode(" ",mb_substr($node->body['und'][0]['value'],0,100)));
	$keywords=array_unique($keywords);
	$keywords[]='обьявления';
	 $taxonomy=taxonomy_term_load_multiple($node->taxonomy);
	  foreach($taxonomy as $t)
	    {
	    $keywords[]=$t->name;
	    }
	#pre($keywords);
                    $page_keywords = array(
                         '#type' => 'html_tag',
                         '#tag' => 'meta',
                         '#attributes' => array(
                          'name' => 'keywords',
                          'content' => implode(",",$keywords),
                            )
                      );
                drupal_add_html_head($page_keywords, 'page_keywords');	  
                
	#pre($node);
	}
	}
	if((arg(0)=='taxonomy')&&(arg(1)=='term'))
	{
	$term=taxonomy_term_load(arg(2));
	if($term->vid==12)
	  {
	 #pre($page['content']);
	  // title
	$title = array(
                         '#type' => 'html_tag',
                         '#tag' => 'title',
                         '#value' => $term->name.' | Инфопарк Обьявления',
                          
                      );
                      drupal_add_html_head($title, 'title');  
           //metadescription            
         $meta_description = array(
			'#type' => 'html_tag',
			'#tag' => 'meta',
			'#attributes' => array(
				'name' => 'description',
				'content' =>  $term->description
			)
		);            
	drupal_add_html_head($meta_description, 'meta_description');  	       
	//key-words
	$keywords=array();
	$keywords=array_merge($keywords,array(0=>$term->name));
	 #pre($keywords);
	if(!empty($term->description))$keywords=array_merge($keywords,explode(" ",trim($term->description)));
	$keywords=array_unique($keywords);
	$keywords[]='Инфопарк';$keywords[]='обьявления';
	
                    $page_keywords = array(
                         '#type' => 'html_tag',
                         '#tag' => 'meta',
                         '#attributes' => array(
                          'name' => 'keywords',
                          'content' => implode(", ",$keywords),
                            )
                      );
                drupal_add_html_head($page_keywords, 'page_keywords');	  
	  }
	}
	

}


function get_city_url_by_id($id) {
global $infopark;
$cities_list=$infopark->cities_list();
return ($cities_list[$id]?$cities_list[$id]->url:'http://www.infopark.com.ua');
	/*$city_urls = array (
		0 => "http://www.infopark.com.ua",
		20 => "http://www.kharkiv.infopark.com.ua",
		21 => 'http://www.kiev.infopark.com.ua',
		41 => 'http://www.odessa.infopark.com.ua',
		57 => 'http://www.kerch.infopark.com.ua'
	);

	return $city_urls[$id];*/

}
###########################################3
function epimetheus_preprocess_html(&$variables) 
    {

    }
function back_btn()
{
return '<div class="closepanel"><span onclick="close_filters()" class="filters_btn1">Свернуть</span></div>';
}
#function _fb_vk_comments()
{
    #pre($_SERVER);
$out='<ul class="com_tabs"><li class="tabvk" onclick="sw_com(\'vk\')">VK</li><li class="tabfb" onclick="sw_com(\'fb\')">FB</li></ul>
<div class="fb com_box"><div class="fb-comments" data-href="http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'].'" data-num-posts="50" data-width="auto"></div></div>
<div class="vk com_box">
<!-- Put this div tag to the place, where the Comments block will be -->
<div id="vk-comments"></div></div>
<script type="text/javascript">
VK.Widgets.Comments("vk-comments", {limit: 10, width: "auto", attach: "*"});


jQuery(document).ready(function() {
//jQuery(\'.fb\').hide();
jQuery(\'.fb\').css(\'visibility\',\'hidden\');
jQuery(\'.fb\').css(\'height\',\'0\');
jQuery(\'.tabvk\').addClass("active_tab");

});
</script>';
return $out;
}
function draw_aboutus_menu($aboutus_nid)
{
 if((arg(0)=='node')&&(arg(1)==$aboutus_nid))
 {
 $menu_r = db_select('menu_links' , 'ml');
 $menu_r->leftjoin('menu_links','ml1','ml1.mlid=ml.plid');
 $menu_r->condition('ml1.link_path' , 'node/'.$aboutus_nid)
  ->fields('ml')
  ->orderby('weight');
  $menu_r_r=$menu_r->execute();
  $out="<ul class='about_menu'>";
 while($m=$menu_r_r->fetchObject())
 {
	
	$out.= "<li>".l($m->link_title,$m->link_path).'</li>';
 }
 $out.= "</ul>";
 return $out;
 }
}
/**
 * print_r of array in <pre> tags
 * @param array $array
 * @param boolean $die
 */
function pre($array,$die=false)
{

print "<pre>";
print_r($array);
print "</pre><hr>";
if($die)die();

}
function russian_month($id)
{
#print $id."<hr>";
  $months=array('none','Январь','Февраль','Март','Апрель','Май','Июнь','Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь');
  return $months[$id];
}
function _draw_logo()
{
return '<div class="logon"><a href="http://'.$_SERVER['SERVER_NAME'].'" title="Афиша: события, концерты, спектакли, галереи | Инфопарк афиша. Билеты на концерты."><img src="/misc/images/logo.png" alt="Афиша: события, концерты, спектакли, галереи | Инфопарк афиша Харькова. Билеты на концерты" title="Афиша: события, концерты, спектакли, галереи | Инфопарк афиша Харькова. Билеты на концерты"></a></div>';
}
function prep_text($text)
{
    return str_replace('"','`',$text);
}
function template_frontpage_events()
{
    global $infopark;
    $days=$infopark->_front_get_event_days();
      
   $edays=$infopark->rebuild_days($days);
 
       $out='<div id="front_events">'.$infopark->_front_events_cal($days);
      $out.='<div class="ft_h_tbl">
          <div class="front_events_affishes">'.$infopark->_front_events_affishes($edays).'</div>
          <div class="front_draw_events_list">'.$infopark->_front_draw_events_list($edays).'</div>
          
          
          </div>'
              ."</div>";
      
    return '<div class="front_engine">'
            . ''.$out.'</div><a href="/events" class="bigmore">Смотреть все афиши</a>
    <script>jQuery( document ).ready(function() {
front_events_init();
});</script>';
    
}
/**
 * Block Afishes on FrontPage
 * **/
/*
function _front_events_affishes($days,$current_city,$cities_list)
{
    global $infopark;
     $out='';
        $first=1;
        $all_events[]=array();
        foreach($days as $d)
        {
            $events=$infopark->_front_get_events($d->nids,$d->date);
            $all_events=array_merge($all_events,$events);
          #  pre($events);
            $out.='
                <div class="front_events_box box_'.$d->date.'">'._front_draw_events($events).'</div>';
            $first=0;
            
        }      
        return $out;
        #$out.='</ul>';
    #urn '<div style="border:solid black 1px;">Events<br>'.$out.'</div>';
    
}*/
/*function _front_events_cal($days)
{
    $out='<ul class="front_events_dates">
            <li class="disabled_arrow front_date_arrows"  onclick="sw_li_period('.$days[0]->date.',\'prev\')"><</li>';
        global $conf;
        $first=1;
        foreach($days as $d)
        {
          
            $t=strtotime($d->date);
            $out.='<li class="date_'.$d->date.($first?' active_li_date':'').'" onclick="sw_event_date('.$d->date.')">'.date('j',$t).' '.$conf['month_names'][date('n',$t)-1]
                    .'<br>'.$conf['week_days'][date('N',$t)-1]
                    .'<p style="color:Red" title="Количество событий">'.$d->events_count.'</p></li>';
            $first=0;
            
        }   
        $out.='<li class="front_date_arrows" onclick="sw_li_period('.$d->date.',\'next\')">></li></ul>';
 return $out;
}*/
function _front_get_events($nids,$date,$current_city,$cities_list)
{
    global $infopark;
    $events=$infopark->_front_get_events($nids,$date);
        
        
   return $infopark->_front_draw_events($events); 
}
function template_frontpage_places()
{
    drupal_add_js('misc/front.js');
    global $infopark;
    # $cc=$infopark->get_city_by_url();
  #  $places=$infopark->_front_get_places();
    //$places=_spec_places_get_places(0, $cc['tid']);
   $days=$infopark->_front_get_event_days();
   $edays=$infopark->rebuild_days_place($days);
   
      $out='<div id="front_places">'.$infopark->_front_places_cal($days);
     $out.='<div class="ft_h_tbl">
         
         <div class="front_places_affishes">'.$infopark->_front_places_affishes($edays).'</div>
         <div class="front_draw_places_list">'.$infopark->_front_draw_places_list($edays).'</div>
             
                  </div>'
             ."</div>";
      $header[]=l('Развлекательные центры','places?category=40');
      $header[]=l('Концертные залы','places?category=16');
      $header[]=l('Театры','places?category=8');
      #'.l('Места','places',array('attributes'=>array('title'=>''))).'
    return '<div class="front_engine"><h2 class="front_title">'.implode('&nbsp;&nbsp;',$header).'</h2>'
           . ''.$out.'</div>
    <script>jQuery( document ).ready(function() {front_places_init();});</script>';
  return '<div style="border:solid black 1px;"><h2>Места</h2>'._front_draw_places($places).'</div>';
    
}

function template_frontpage_gallery()
{
    global $infopark;
    $photos=$infopark->_front_get_gallery();
    return '<div class="front_engine"><h2 class="front_title">'.l('Галереи','gallery-collections/galleries',array('attributes'=>array('title'=>'Галереи: свадьба, party, вечеринка, session, выступление в клубах  | Инфопарк афиша. Билеты на концерты.'))).'</h2>'
    ._front_draw_gallery($photos)
    .'</div>';
    
}
function _front_draw_gallery($photos)
{
  
    $out='<table class="front_gallery_tbl">
        <tr>
            <td>'._front_photo(array_shift($photos),'small').'</td>
            <td>'._front_photo(array_shift($photos),'small').'</td>
            <td>'._front_photo(array_shift($photos),'small').'</td>    
        </tr>
        <tr>
            <td>'._front_photo(array_shift($photos),'small').'</td>
            <td>'._front_photo(array_shift($photos),'small').'</td>
            <td>'._front_photo(array_shift($photos),'small').'</td>    
        </tr>
        

        </table>';
    # <tr><td>'._front_photo(array_shift($photos),'small').'</td><td>'._front_photo(array_shift($photos),'small').'</td></tr>
    return $out;
}
function _front_photo($photo,$type)
{
    if($type=='large')
    {
        $src=image_style_url('original',$photo->uri);
        $width=335;
    }else{
         $src=image_style_url('200_200',$photo->uri);
         $width='100%';
    }
    return l('<img src="'.$src.'" width="'.$width.'" height="'.$height.'">','media-gallery/detail/'.$photo->nid.'/'.$photo->fid,array('html'=>true,'attributes'=>array('title'=>$photo->title)));
    
}
function template_frontpage_footer()
{
    global $infopark;
    
    $out='<div class="front_footer">';
    $out.='<h5 class="footer_title">ИНФОПАРК - ИСТОЧНИК ПОЗИТИВА</h5>';
    $cities=$infopark->cities_list();
    foreach($cities as $city)
    {
        $out.=l($city->name,$city->url)."&nbsp;&bull;&nbsp;";
    }
    $out.='<hr>';
      foreach(taxonomy_get_tree(5) as $cc)
      {
          $out.=l($cc->name,'places?category='.$cc->tid)."&nbsp;&bull;&nbsp;";
      }
      $out.='<br><br><p>Copyright © 2011-2014 Infopark.ua  Все права защищены. При использовании материала ссылка на сайт обязательна. моб. (097)961-95-59; (050)403-09-99.<br>
e-mail: <a href="mailto:web@spreklama.com.ua">web@spreklama.com.ua</a></p><br>';
      $out.='</div>';
      #    $categories_names[$cc->tid]=$cc->name;
      
      return $out;
}



function template_footer()
{
    global $infopark;
    
        $out='<div class="small_footer">'; 
        $out.='Copyright © 2011-2014 Infopark.ua  Все права защищены. При использовании материала ссылка на сайт обязательна.<br>моб. (097)961-95-59; (050)403-09-99. 
        e-mail: <a href="mailto:web@spreklama.com.ua">web@spreklama.com.ua</a>';
        $out.='</div>';
      return $out;
}


function template_top_events()
{
// drupal_add_js('https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.js');
   // drupal_add_js('https://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.js');
  drupal_add_js('misc/jquery.coverflow.js');
     drupal_add_js('misc/jquery.interpolate.js');
      drupal_add_js('misc/jquery.mousewheel.js');
       drupal_add_js('misc/jquery.touchSwipe.min.js');
		drupal_add_js('misc/reflection.js');
        drupal_add_js('https://cdnjs.cloudflare.com/ajax/libs/pagedown/1.0/Markdown.Converter.min.js');
     
    global $infopark;
    
    $step=20;
    $events=$infopark->get_top_events($step,0);
    $out='';
   $out.="<script>jQuery(function() {
                                if ($.fn.reflect) {
				//	$('#coverflow .cover').reflect();
				}

				jQuery('#coverflow').coverflow({
					index:			0,
					width:			420,
					height:			340,
					visible:		'density',
                                        density:                3,
					selectedCss:	{	opacity: 1	},
					outerCss:		{	opacity: .5	},

					select:		function(event, cover) {
						var img = jQuery(cover).children().andSelf().filter('img').last();
                                                jQuery('#coverflow a h5').hide();
						jQuery(cover).children().andSelf().filter('h5').last().show();
					},
                                        
				});
		
		});</script>";
 
    $out.='<div class="coverflow_wrapper"><div id="coverflow">';
     foreach($events as $event)
    {
        $out.=$infopark->_front_top_event($event);
    }
    $out.='</div></div> ';
   
    /*
    $out='<div class="top_arrows_box">
     <span class="top_arrows top_arrow_prev" style="float:left;" onclick="top_init(\'prev\');"></span>
     <span class="top_arrows top_arrow_next" style="float:right;" onclick="top_init(\'next\');"></span>
     </div>
     <table class="top_tbl"><tr></tr></table>
        <table class="top_load"><tr>';
    foreach($events as $event)
    {
        $out.='<td>'.$infopark->_front_top_event($event)."</td>";
    }
    $out.='</tr></table>';
    $out.='<script>top_init(0);</script>';
   */
    return $out;
}
function template_draw_filter_title($title)
{
    //return '<h1 id="filter_title">'.$title.'</h1>';
    
}
function social_plugings()
{
    return '<!-- AddThis Button BEGIN -->
                    <div class="addthis_toolbox addthis_default_style addthis_32x32_style">
                    <a class="addthis_button_preferred_1"></a>
                    <a class="addthis_button_preferred_2"></a>
                    <a class="addthis_button_preferred_3"></a>
                    <a class="addthis_button_preferred_4"></a>
                    <a class="addthis_button_compact"></a>
                    <a class="addthis_counter addthis_bubble_style"></a>
                    </div>
                    <script type="text/javascript">var addthis_config = {"data_track_addressbar":true};</script>
                    <script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-5065df4b159981b7"></script>
                    <!-- AddThis Button END -->';
}
    ?>